const https = require('https');

const getPublicIPAddress = (callback) => {
    const options = {
        hostname: 'api.ipify.org',
        port: 443,
        path: '/', 
        method: 'GET'
    };

    const req = https.request(options, (res) => {
        let data = '';
        res.on('data', (chunk) => {
            data += chunk;
        });
        res.on('end', () => {
            callback(null, data);
        });
    });

    req.on('error', (error) => {
        callback(error);
    });

    req.end();
}

module.exports = {
    getPublicIPAddress,
}